//
//  GYMineProductInfoViewModel.m
//  GYDemo
//
//  Created by mac on 2018/3/30.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "GYMineProductInfoViewModel.h"
#import "Head.h"

@implementation GYMineProductInfoModel
@end

@implementation GYMineProductInfoViewModel
#pragma mark - getter and setter
-(NSMutableArray *)datas
{
    if (!_datas) {
        _datas = [NSMutableArray new];
    }
    return _datas;
}
#pragma mark - method
-(void)requestDatas:(NSMutableDictionary *)para
{
    @WeakSelf;
    NSString *interface = @"mySaleProduct";
    NSString *page = para[@"page"];
    [[InterfaceManager shareInterface]requetInterface:interface withParameter:para handler:^(NSDictionary *info, InterfaceStatusModel *infoModel) {
        NSDictionary *data = infoModel.data;
        if ([data isKindOfClass:[NSDictionary class]]) {
            NSArray *datalist = data[@"datalist"];
            if ([datalist isKindOfClass:[NSArray class]]) {
                NSMutableArray *arr;
                if ([page isEqualToString:@"1"]) {
                    arr = [NSMutableArray new];
                }else{
                    arr = _datas;
                }
                for (NSDictionary *dic in datalist) {
                    GYMineProductInfoModel *model = [GYMineProductInfoModel yy_modelWithJSON:dic];
                    [arr addObject:model];
                }
                [selfp setDatas:arr];
            }
        }
    }];
}
//-(void)requestUp:(GYMineProductInfoModel *)product
//{
//    @WeakSelf;
//    NSString *interface = @"undownDelSaleProduct";
//    NSString *proid = [NSString stringWithFormat:@"%ld",product.id];
//    NSString *down = @"1";
//    NSMutableDictionary *para = [NSMutableDictionary new];
//    [para setObject:proid forKey:@"id"];
//    [para setObject:down forKey:@"down"];
//    [[InterfaceManager shareInterface]requetInterface:interface withParameter:para handler:^(NSDictionary *info, InterfaceStatusModel *infoModel) {
//        if ([selfp.datas containsObject:product]) {
//            NSInteger index = [selfp.datas indexOfObject:product];
//            GYMineProductInfoModel *model = product;
//            model.down = down.integerValue;
//            NSMutableArray *arr = selfp.datas;
//            [arr replaceObjectAtIndex:index withObject:model];
//            [selfp setDatas:arr];
//        }
//    }];
//}
//-(void)requestDown:(GYMineProductInfoModel *)product
//{
//    @WeakSelf;
//    NSString *interface = @"undownDelSaleProduct";
//    NSString *proid = [NSString stringWithFormat:@"%ld",product.id];
//    NSString *down = @"2";
//    NSMutableDictionary *para = [NSMutableDictionary new];
//    [para setObject:proid forKey:@"id"];
//    [para setObject:down forKey:@"down"];
//    [[InterfaceManager shareInterface]requetInterface:interface withParameter:para handler:^(NSDictionary *info, InterfaceStatusModel *infoModel) {
//        if ([selfp.datas containsObject:product]) {
//            NSInteger index = [selfp.datas indexOfObject:product];
//            GYMineProductInfoModel *model = product;
//            model.down = down.integerValue;
//            NSMutableArray *arr = selfp.datas;
//            [arr replaceObjectAtIndex:index withObject:model];
//            [selfp setDatas:arr];
//        }
//    }];
//}
//-(void)requestDelete:(GYMineProductInfoModel *)product
//{
//    @WeakSelf;
//    NSString *interface = @"undownDelSaleProduct";
//    NSString *proid = [NSString stringWithFormat:@"%ld",product.id];
//    NSString *down = @"3";
//    NSMutableDictionary *para = [NSMutableDictionary new];
//    [para setObject:proid forKey:@"id"];
//    [para setObject:down forKey:@"down"];
//    [[InterfaceManager shareInterface]requetInterface:interface withParameter:para handler:^(NSDictionary *info, InterfaceStatusModel *infoModel) {
//        NSMutableArray *arr = selfp.datas;
//        [arr removeObject:product];
//        [selfp setDatas:arr];
//    }];
//}

-(void)requestUpIndex:(NSInteger)index
{
    GYMineProductInfoModel *product = self.datas[index];
    @WeakSelf;
    NSString *interface = @"undownDelSaleProduct";
    NSString *proid = [NSString stringWithFormat:@"%ld",product.id];
    NSString *down = @"1";
    NSMutableDictionary *para = [NSMutableDictionary new];
    [para setObject:proid forKey:@"id"];
    [para setObject:down forKey:@"down"];
    [[InterfaceManager shareInterface]requetInterface:interface withParameter:para handler:^(NSDictionary *info, InterfaceStatusModel *infoModel) {
        if ([selfp.datas containsObject:product]) {
            product.down = down.integerValue;
            NSMutableArray *arr = selfp.datas;
            [arr replaceObjectAtIndex:index withObject:product];
            [selfp setDatas:arr];
        }
    }];
}
-(void)requestDownIndex:(NSInteger)index
{
    GYMineProductInfoModel *product = self.datas[index];
    @WeakSelf;
    NSString *interface = @"undownDelSaleProduct";
    NSString *proid = [NSString stringWithFormat:@"%ld",product.id];
    NSString *down = @"2";
    NSMutableDictionary *para = [NSMutableDictionary new];
    [para setObject:proid forKey:@"id"];
    [para setObject:down forKey:@"down"];
    [[InterfaceManager shareInterface]requetInterface:interface withParameter:para handler:^(NSDictionary *info, InterfaceStatusModel *infoModel) {
        if ([selfp.datas containsObject:product]) {
            product.down = down.integerValue;
            NSMutableArray *arr = selfp.datas;
            [arr replaceObjectAtIndex:index withObject:product];
            [selfp setDatas:arr];
        }
    }];
}
-(void)requestDeleteIndex:(NSInteger)index
{
    GYMineProductInfoModel *product = self.datas[index];
    @WeakSelf;
    NSString *interface = @"undownDelSaleProduct";
    NSString *proid = [NSString stringWithFormat:@"%ld",product.id];
    NSString *down = @"3";
    NSMutableDictionary *para = [NSMutableDictionary new];
    [para setObject:proid forKey:@"id"];
    [para setObject:down forKey:@"down"];
    [[InterfaceManager shareInterface]requetInterface:interface withParameter:para handler:^(NSDictionary *info, InterfaceStatusModel *infoModel) {
        NSMutableArray *arr = selfp.datas;
        [arr removeObject:product];
        [selfp setDatas:arr];
    }];
}
@end
